package com.byit.shrio.session;

import com.byit.domain.SysUser;

import javax.servlet.http.HttpSession;

/**
 * @author marker
 **/
public final class SessionHelper {

    /**
     * 获取登录用户
     *
     * @param session 会话
     * @return
     */
    public static SysUser getUser(HttpSession session) {
        if (session == null) return null;
        SysUser user = (SysUser) session.getAttribute(SessionAttr.userInfo);
        if (null != user) {
            return user;
        }
        return null;
    }


    /**
     * 获取登录用户ID
     *
     * @param session 会话
     * @return
     */
    public static Long getUserId(HttpSession session) {
        if (session == null) return null;
        Long userId = (Long) session.getAttribute(SessionAttr.userId);
        if (null != userId) {
            return userId;
        }
        return null;
    }

    /**
     * 获取登录用户公司ID
     *
     * @param session 会话
     * @return
     */
    public static Long getCompanyId(HttpSession session) {
        if (session == null) return null;
        return (Long) session.getAttribute(SessionAttr.companyId);
    }

    /**
     * 获取RoleId用户角色
     *
     * @param session 会话
     * @return
     */
    public static Long getRoleId(HttpSession session) {
        if (session == null) return null;
        return (Long) session.getAttribute(SessionAttr.userRoleId);
    }

    /**
     * 获取登录用户名
     *
     * @param session 会话
     * @return
     */
    public static String getLoginName(HttpSession session) {
        if (session == null) return null;
        return (String) session.getAttribute(SessionAttr.loginName);
    }

    /**
     * 获取登录用户姓名
     *
     * @param session 会话
     * @return
     */
    public static String getUserName(HttpSession session) {
        if (session == null) return null;
        return (String) session.getAttribute(SessionAttr.userName);
    }


}
